﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PBO.Data.Effect.MoveEffect
{
    public class HiddenPower
    {

        #region 催醒

        //http://wiki.52poke.com/wiki/催醒计算

        public static BattleType GetHiddenType(IStats iv)
        {
            var array = (from type in BaseStats.Types select iv[type]).ToArray();
            int id = GetHiddenTypeId(array);
            return (BattleType)(id + 2);
        }

        public static int GetHiddenPower(IStats iv)
        {
            var array = (from type in BaseStats.Types select iv[type]).ToArray();
            return GetHiddenPower(array);
        }

        /// <summary>
        /// 顺序 HP, 攻击, 防御, 速度, 特攻, 特防
        /// </summary>
        public static byte GetHiddenTypeId(int[] array)
        {
            int sum = 0;
            for (int i = 0; i < array.Length; i++)
            {
                sum += (array[i] & 1) << i;
            }
            return Convert.ToByte(sum * 15 / 63);
        }

        public static byte GetHiddenPower(int[] array)
        {
            int sum = 0;
            for (int i = 0; i < array.Length; i++)
            {
                sum += array[i] % 4 > 1 ? 1 << i : 0;
            }
            return Convert.ToByte(sum * 40 / 63 + 30);
        }

        #endregion

    }
}
